package com.mengxin.secondkill.message;

import com.mengxin.secondkill.constants.RespCode;
import com.mengxin.secondkill.exception.ServiceException;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author mengxin
 * @date 2020/12/12 18:08
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    private int code;

    private T data;

    private String message;

    public Result(ServiceException serviceException){
        this.code = serviceException.getCode();
        this.message = serviceException.getMessage();
    }

    public Result(IllegalArgumentException serviceException){
        this.code = RespCode.COMMON_FAIL_CODE;
        this.message = serviceException.getMessage();
    }

    public Result(T data){
        this.data = data;
    }
}
